//
//  DXEmotonModel.swift
//  weiBoOfSwift
//
//  Created by simon on 15/12/15.
//  Copyright © 2015年 simon. All rights reserved.
//

import UIKit

class DXEmotonModel: NSObject,NSCoding{

//    图片文字简体
    var chs:String?
//    图片文字繁体
    var cht:String?
//    图片名称
    var png:String?
//    图片类型
    var type:String?
//    emoji图片的编码
    var code:String?
//   图片的全路径
     var img:String?
//    判断是否是emoji表情
    var isEmoji:Bool {
        get{
            if type == "1"{
            
            return true
            }else {
            return false
            
            }
        
        }
    }
    
    init(dict:[String:AnyObject]){
    super.init()
//        字典转模型
    setValuesForKeysWithDictionary(dict)
    
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    required init?(coder aDecoder: NSCoder) {
         chs = aDecoder.decodeObjectForKey("chs") as? String
         cht = aDecoder.decodeObjectForKey("cht") as? String
         png = aDecoder.decodeObjectForKey("png") as? String
         type = aDecoder.decodeObjectForKey("type") as? String
         code = aDecoder.decodeObjectForKey("code") as? String
         img = aDecoder.decodeObjectForKey("img") as? String
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
           aCoder.encodeObject(chs, forKey: "chs")
           aCoder.encodeObject(cht, forKey: "cht")
           aCoder.encodeObject(png, forKey: "png")
           aCoder.encodeObject(type, forKey: "type")
           aCoder.encodeObject(code, forKey: "code")
           aCoder.encodeObject(img, forKey: "img")
    }
    
//    重写匹配方法
    override func isEqual(object: AnyObject?) -> Bool {
        guard let other = object as? DXEmotonModel else{
        return super.isEqual(object)
        }
        
        if other.isEmoji == isEmoji{
        
        if other.isEmoji {
           return (other.code! as NSString).isEqualToString(code!)
        }else{
            return (other.chs! as NSString).isEqualToString(chs!) || (other.cht! as NSString).isEqualToString(cht!)
            }
        
        }
        
    
    return super.isEqual(object)
    }
}
